package com.work.music.dao;

import com.work.music.entity.IntegralLog;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface IntegralLogMapper {
    @Delete({
        "delete from music_integral_log",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into music_integral_log (uid, addtime, ",
        "addip, integral, ",
        "typeid, mobile_model, ",
        "mobile_name)",
        "values (#{uid,jdbcType=BIGINT}, #{addtime,jdbcType=TIMESTAMP}, ",
        "#{addip,jdbcType=VARCHAR}, #{integral,jdbcType=BIGINT}, ",
        "#{typeid,jdbcType=BIGINT}, #{mobileModel,jdbcType=VARCHAR}, ",
        "#{mobileName,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(IntegralLog record);

    @Select({
        "select",
        "id, uid, addtime, addip, integral, typeid, mobile_model, mobile_name",
        "from music_integral_log",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR),
        @Result(column="integral", property="integral", jdbcType=JdbcType.BIGINT),
        @Result(column="typeid", property="typeid", jdbcType=JdbcType.BIGINT),
        @Result(column="mobile_model", property="mobileModel", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile_name", property="mobileName", jdbcType=JdbcType.VARCHAR)
    })
    IntegralLog selectByPrimaryKey(Long id);

    @Select({
        "select",
        "id, uid, addtime, addip, integral, typeid, mobile_model, mobile_name",
        "from music_integral_log"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR),
        @Result(column="integral", property="integral", jdbcType=JdbcType.BIGINT),
        @Result(column="typeid", property="typeid", jdbcType=JdbcType.BIGINT),
        @Result(column="mobile_model", property="mobileModel", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile_name", property="mobileName", jdbcType=JdbcType.VARCHAR)
    })
    List<IntegralLog> selectAll();

    @Update({
        "update music_integral_log",
        "set uid = #{uid,jdbcType=BIGINT},",
          "addtime = #{addtime,jdbcType=TIMESTAMP},",
          "addip = #{addip,jdbcType=VARCHAR},",
          "integral = #{integral,jdbcType=BIGINT},",
          "typeid = #{typeid,jdbcType=BIGINT},",
          "mobile_model = #{mobileModel,jdbcType=VARCHAR},",
          "mobile_name = #{mobileName,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(IntegralLog record);

    @Select("select " +
            "l.id,l.integral,l.addtime,t.`desc` " +
            "from music_integral_type t, music_integral_log l " +
            "where l.uid=#{uid} and t.id=l.typeid " +
            "order by l.addtime desc limit #{page},#{count}")
    List<Map<String, Object>> selectByUid(@Param("uid") long uid, @Param("page") int page, @Param("count") int count);
}